package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityXfRecordProcessExxx;
import com.ocom.common.entity.pay.EntityXfRecordProcessExtend;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoXfRecordProcessExtend;
import com.ocom.payhandle.service.XfRecordProcessExtendService;
import org.springframework.stereotype.Service;


@Service
public class XfRecordProcessExtendServiceImpl extends ServiceImpl<IDaoXfRecordProcessExtend, EntityXfRecordProcessExtend> implements XfRecordProcessExtendService {


    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB)
    public boolean insertEntityXfRecordExtend(Long companyId, EntityXfRecordProcessExtend entityXfRecordProcessExtend) {
        return this.save(entityXfRecordProcessExtend);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB)
    public boolean updateEntityXfRecordExtend(Long companyId, EntityXfRecordProcessExtend entityXfRecordProcessExtend) {
        UpdateWrapper<EntityXfRecordProcessExtend> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("order_id",entityXfRecordProcessExtend.getOrderId());
        return this.update(entityXfRecordProcessExtend,updateWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
    public EntityXfRecordProcessExtend getExtendInfo(Long companyId, Long orderId) {
        QueryWrapper<EntityXfRecordProcessExtend> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("order_id",orderId);
        return this.getOne(queryWrapper);
    }



    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
    public boolean updateCancelState(Long companyId,Long orderId,Integer cancelState) {
        UpdateWrapper<EntityXfRecordProcessExtend> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("com_id", companyId);
        updateWrapper.eq("order_id", orderId);
        updateWrapper.set("cancel_state", cancelState);
        return this.update(updateWrapper);
    }

}
